package org.example.controller.defaultDir;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.ResponseResult;
import org.example.model.util.dtos.UtilInfoDto;
import org.example.model.util.vos.ModifyUtilInfoVo;
import org.example.controller.common.permission.PermissionControl;
import org.example.service.util.UtilInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 常用工具信息表现层
 */
@CrossOrigin
@RestController
@RequestMapping("/util-info")
@Api(value = "常用工具信息接口", tags = {"常用工具信息接口"})
@PermissionControl(Name = "常用工具", Order = 3)
public class UtilInfoController{

    @Autowired
    private UtilInfoService utilInfoService;

    /**
     * 添加一条工具信息
     */
    @PostMapping
    @ApiOperation("添加一条工具信息")
    @PermissionControl(Parent = "常用工具", Name = "添加", Order = 1)
    public ResponseResult<Boolean> InsertUtilInfo(@RequestBody ModifyUtilInfoVo modifyUtilInfoVo){
        return utilInfoService.InsertUtilInfo(modifyUtilInfoVo);
    }

    /**
     * 根据id修改一条工具信息
     */
    @PutMapping
    @ApiOperation("根据id修改一条工具信息")
    @PermissionControl(Parent = "常用工具", Name = "修改", Order = 3)
    public ResponseResult<Boolean> UpdateUtilInfoById(@RequestBody ModifyUtilInfoVo modifyUtilInfoVo){
        return utilInfoService.UpdateUtilInfoById(modifyUtilInfoVo);
    }

    /**
     * 根据id删除一条工具信息
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据id删除一条工具信息")
    @PermissionControl(Parent = "常用工具", Name = "删除", Order = 2)
    public ResponseResult<Boolean> DeleteUtilInfoById(@PathVariable Integer id){
        return utilInfoService.DeleteUtilInfoById(id);
    }

    /**
     * 获取所有的工具信息列表
     */
    @GetMapping("/util-list")
    @ApiOperation("获取所有的工具信息列表")
    @PermissionControl(Parent = "常用工具", Name = "查询", Order = 4)
    public ResponseResult<List<UtilInfoDto>> GetUtilInfoList(){
        return utilInfoService.GetUtilInfoList();
    }
}
